load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")

go_library(
    name = "backupccl",
    srcs = [
        "alter_backup_planning.go",
        "alter_backup_schedule.go",
        "backup_job.go",
        "backup_metrics.go",
        "backup_planning.go",
        "backup_planning_tenant.go",
        "backup_processor.go",
        "backup_processor_planning.go",
        "backup_span_coverage.go",
        "backup_telemetry.go",
        "create_scheduled_backup.go",
        "file_sst_sink.go",
        "generative_split_and_scatter_processor.go",
        "key_rewriter.go",
        "restoration_data.go",
        "restore_data_processor.go",
        "restore_job.go",
        "restore_online.go",
        "restore_planning.go",
        "restore_processor_planning.go",
        "restore_progress.go",
        "restore_schema_change_creation.go",
        "restore_span_covering.go",
        "revision_reader.go",
        "schedule_exec.go",
        "schedule_pts_chaining.go",
        "show.go",
        "system_schema.go",
        "targets.go",
        ":gen-targetscope-stringer",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/ccl/backupccl",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/build",
        "//pkg/ccl/backupccl/backupbase",
        "//pkg/ccl/backupccl/backupdest",
        "//pkg/ccl/backupccl/backupencryption",
        "//pkg/ccl/backupccl/backupinfo",
        "//pkg/ccl/backupccl/backuppb",
        "//pkg/ccl/backupccl/backupresolver",
        "//pkg/ccl/backupccl/backuputils",
        "//pkg/ccl/kvccl/kvfollowerreadsccl",
        "//pkg/ccl/multiregionccl",
        "//pkg/ccl/storageccl",
        "//pkg/ccl/utilccl",
        "//pkg/cloud",
        "//pkg/cloud/cloudcheck",
        "//pkg/cloud/cloudpb",
        "//pkg/cloud/cloudprivilege",
        "//pkg/clusterversion",
        "//pkg/featureflag",
        "//pkg/jobs",
        "//pkg/jobs/joberror",
        "//pkg/jobs/jobspb",
        "//pkg/jobs/jobsprofiler",
        "//pkg/jobs/jobsprotectedts",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/bulk",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver/batcheval",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/kv/kvserver/protectedts",
        "//pkg/kv/kvserver/protectedts/ptpb",
        "//pkg/multitenant/mtinfopb",
        "//pkg/roachpb",
        "//pkg/scheduledjobs",
        "//pkg/scheduledjobs/schedulebase",
        "//pkg/security/username",
        "//pkg/server/serverpb",
        "//pkg/server/telemetry",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/catpb",
        "//pkg/sql/catalog/colinfo",
        "//pkg/sql/catalog/dbdesc",
        "//pkg/sql/catalog/descbuilder",
        "//pkg/sql/catalog/descidgen",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/descs",
        "//pkg/sql/catalog/funcdesc",
        "//pkg/sql/catalog/ingesting",
        "//pkg/sql/catalog/multiregion",
        "//pkg/sql/catalog/nstree",
        "//pkg/sql/catalog/rewrite",
        "//pkg/sql/catalog/schemadesc",
        "//pkg/sql/catalog/systemschema",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/catalog/typedesc",
        "//pkg/sql/doctor",
        "//pkg/sql/execinfra",
        "//pkg/sql/execinfrapb",
        "//pkg/sql/exprutil",
        "//pkg/sql/isql",
        "//pkg/sql/parser",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/pgwire/pgnotice",
        "//pkg/sql/physicalplan",
        "//pkg/sql/privilege",
        "//pkg/sql/protoreflect",
        "//pkg/sql/rowenc",
        "//pkg/sql/rowexec",
        "//pkg/sql/schemachanger/scbackup",
        "//pkg/sql/sem/builtins",
        "//pkg/sql/sem/catconstants",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sqlclustersettings",
        "//pkg/sql/sqlerrors",
        "//pkg/sql/stats",
        "//pkg/sql/syntheticprivilege",
        "//pkg/sql/types",
        "//pkg/storage",
        "//pkg/storage/enginepb",
        "//pkg/util/admission",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/bulk",
        "//pkg/util/ctxgroup",
        "//pkg/util/envutil",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/interval",
        "//pkg/util/iterutil",
        "//pkg/util/json",
        "//pkg/util/log",
        "//pkg/util/log/eventpb",
        "//pkg/util/log/logutil",
        "//pkg/util/log/severity",
        "//pkg/util/metamorphic",
        "//pkg/util/metric",
        "//pkg/util/mon",
        "//pkg/util/pprofutil",
        "//pkg/util/protoutil",
        "//pkg/util/randutil",
        "//pkg/util/retry",
        "//pkg/util/span",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//types",
        "@com_github_kr_pretty//:pretty",
        "@com_github_robfig_cron_v3//:cron",
        "@org_golang_x_exp//maps",
    ],
)

go_test(
    name = "backupccl_test",
    size = "enormous",
    srcs = [
        "alter_backup_schedule_test.go",
        "alter_backup_test.go",
        "backup_cloud_test.go",
        "backup_intents_test.go",
        "backup_planning_test.go",
        "backup_tenant_test.go",
        "backup_test.go",
        "bench_covering_test.go",
        "bench_test.go",
        "create_scheduled_backup_test.go",
        "data_driven_generated_test.go",  # keep
        "datadriven_test.go",
        "file_sst_sink_test.go",
        "full_cluster_backup_restore_test.go",
        "generative_split_and_scatter_processor_test.go",
        "key_rewriter_test.go",
        "main_test.go",
        "partitioned_backup_test.go",
        "restore_data_processor_test.go",
        "restore_mid_schema_change_test.go",
        "restore_multiregion_rbr_test.go",
        "restore_old_sequences_test.go",
        "restore_old_versions_test.go",
        "restore_online_test.go",
        "restore_planning_test.go",
        "restore_progress_test.go",
        "restore_span_covering_test.go",
        "revision_reader_test.go",
        "schedule_pts_chaining_test.go",
        "show_test.go",
        "system_schema_test.go",
        "tenant_backup_nemesis_test.go",
        "utils_test.go",
    ],
    data = glob(["testdata/**"]) + ["//c-deps:libgeos"],
    embed = [":backupccl"],
    exec_properties = select({
        "//build/toolchains:is_heavy": {"test.Pool": "heavy"},
        "//conditions:default": {"test.Pool": "large"},
    }),
    shard_count = 48,
    deps = [
        "//pkg/base",
        "//pkg/blobs",
        "//pkg/build/bazel",
        "//pkg/ccl",
        "//pkg/ccl/backupccl/backupbase",
        "//pkg/ccl/backupccl/backupdest",
        "//pkg/ccl/backupccl/backupencryption",
        "//pkg/ccl/backupccl/backupinfo",
        "//pkg/ccl/backupccl/backuppb",
        "//pkg/ccl/backupccl/backuptestutils",
        "//pkg/ccl/backupccl/backuputils",
        "//pkg/ccl/kvccl",
        "//pkg/ccl/multiregionccl",
        "//pkg/ccl/multiregionccl/multiregionccltestutils",
        "//pkg/ccl/multitenantccl",
        "//pkg/ccl/partitionccl",
        "//pkg/ccl/storageccl",
        "//pkg/ccl/utilccl",
        "//pkg/cloud",
        "//pkg/cloud/amazon",
        "//pkg/cloud/azure",
        "//pkg/cloud/cloudpb",
        "//pkg/cloud/gcp",
        "//pkg/cloud/impl:cloudimpl",
        "//pkg/cloud/nodelocal",
        "//pkg/clusterversion",
        "//pkg/jobs",
        "//pkg/jobs/jobspb",
        "//pkg/jobs/jobsprotectedts",
        "//pkg/jobs/jobstest",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/bulk",
        "//pkg/kv/kvclient/kvcoord",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver",
        "//pkg/kv/kvserver/closedts",
        "//pkg/kv/kvserver/kvserverbase",
        "//pkg/kv/kvserver/protectedts",
        "//pkg/kv/kvserver/protectedts/ptpb",
        "//pkg/kv/kvserver/protectedts/ptutil",
        "//pkg/multitenant/mtinfopb",
        "//pkg/multitenant/tenantcapabilities",
        "//pkg/roachpb",
        "//pkg/scheduledjobs",
        "//pkg/scheduledjobs/schedulebase",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/security/username",
        "//pkg/server",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/spanconfig",
        "//pkg/sql",
        "//pkg/sql/catalog",
        "//pkg/sql/catalog/bootstrap",
        "//pkg/sql/catalog/catalogkeys",
        "//pkg/sql/catalog/dbdesc",
        "//pkg/sql/catalog/descbuilder",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/catalog/descs",
        "//pkg/sql/catalog/desctestutils",
        "//pkg/sql/catalog/funcdesc",
        "//pkg/sql/catalog/schemadesc",
        "//pkg/sql/catalog/systemschema",
        "//pkg/sql/catalog/tabledesc",
        "//pkg/sql/catalog/typedesc",
        "//pkg/sql/execinfra",
        "//pkg/sql/execinfrapb",
        "//pkg/sql/importer",
        "//pkg/sql/isql",
        "//pkg/sql/parser",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/sql/randgen",
        "//pkg/sql/rowenc",
        "//pkg/sql/sem/eval",
        "//pkg/sql/sem/tree",
        "//pkg/sql/sessiondata",
        "//pkg/sql/sqlclustersettings",
        "//pkg/sql/sqlliveness/slbase",
        "//pkg/sql/stats",
        "//pkg/storage",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/fingerprintutils",
        "//pkg/testutils/jobutils",
        "//pkg/testutils/kvclientutils",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/testcluster",
        "//pkg/util",
        "//pkg/util/admission",
        "//pkg/util/ctxgroup",
        "//pkg/util/encoding",
        "//pkg/util/envutil",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/ioctx",
        "//pkg/util/leaktest",
        "//pkg/util/limit",
        "//pkg/util/log",
        "//pkg/util/log/eventpb",
        "//pkg/util/log/logpb",
        "//pkg/util/mon",
        "//pkg/util/protoutil",
        "//pkg/util/randutil",
        "//pkg/util/retry",
        "//pkg/util/span",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/uuid",
        "//pkg/util/version",
        "//pkg/workload",
        "//pkg/workload/bank",
        "//pkg/workload/histogram",
        "//pkg/workload/workloadsql",
        "@com_github_aws_aws_sdk_go//aws/credentials",
        "@com_github_cockroachdb_cockroach_go_v2//crdb",
        "@com_github_cockroachdb_datadriven//:datadriven",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_errors//oserror",
        "@com_github_cockroachdb_pebble//sstable",
        "@com_github_cockroachdb_pebble//vfs",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//types",
        "@com_github_jackc_pgx_v4//:pgx",
        "@com_github_kr_pretty//:pretty",
        "@com_github_lib_pq//:pq",
        "@com_github_robfig_cron_v3//:cron",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@org_golang_x_sync//errgroup",
    ],
)

stringer(
    name = "gen-targetscope-stringer",
    src = "backup_telemetry.go",
    additional_args = ["-linecomment"],
    typ = "targetScope",
)

genrule(
    name = "gen-backupccl-tests",
    srcs = glob(["testdata/**"]),
    outs = [
        "data_driven_generated_test.go",
    ],
    cmd = """
        $(location //pkg/ccl/backupccl/testgen) \
        -data-driven=$(location data_driven_generated_test.go) 
       """,
    tools = [
        "//pkg/ccl/backupccl/testgen",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)
